/// @file st-rpg.c
/// @brief 
/// @author Moose W. Oler
/// @version v0.1
/// @date 2011-06-04

#include <SDL.h>
#include "st-common.h"
#include "st-graphic.h"
#include "st-rpg.h"

#define ST_IMAGE_COLORKEY_R     0x86
#define ST_IMAGE_COLORKEY_G     0x10
#define ST_IMAGE_COLORKEY_B     0x07

st_state _st_object_SetName(st_object_info* obj, const st_uint8* name);
st_uint8*   _st_object_GetName(const st_object_info* obj, st_uint8* name);

st_state _st_object_SetPosition(st_object_info* obj, const st_vertex_3d* pos);
st_state _st_object_GetPosition(const st_object_info* obj, st_vertex_3d* pos);

st_state _st_object_SetVelocity(st_object_info* obj, const st_vertex_3d* vel);
st_state _st_object_GetVelocity(const st_object_info* obj, st_vertex_3d* vel);

st_state _st_object_SetImage(st_object_info* obj, const st_uint8* imgfile);
st_state _st_object_GetImage(const st_object_info* obj, st_graphic** graphic);

st_state _st_object_OnMoving(st_object_info* obj);




// --------------------------------------------------------------------------
/// @brief 
///
/// @param obj
/// @param name
///
/// @return 
// --------------------------------------------------------------------------
st_state _st_object_SetName(st_object_info* obj, const st_uint8* name)
{
    if (strlen(name) < ST_OBJINFO_NAME_SIZE)
    {
        strcpy(obj->name, name);
        return ST_OK;
    }
    else
    {
        return ST_ERROR;
    }
}

// --------------------------------------------------------------------------
/// @brief 
///
/// @param obj
/// @param name
///
/// @return 
// --------------------------------------------------------------------------
st_uint8*   _st_object_GetName(const st_object_info* obj, st_uint8* name)
{
    if (obj->name != NULL)
    {
        strcpy(name, obj->name);
        return name;
    }
    else
    {
        return NULL;
    }
}

st_state _st_object_SetPosition(st_object_info* obj, const st_vertex_3d* pos)
{
    obj->position.x = pos->x;
    obj->position.y = pos->y;
    obj->position.z = pos->z;
    return ST_OK;
}

st_state _st_object_GetPosition(const st_object_info* obj, st_vertex_3d* pos)
{
    pos->x = obj->position.x;
    pos->y = obj->position.y;
    pos->z = obj->position.z;
    return ST_OK;
}


st_state _st_object_SetVelocity(st_object_info* obj, const st_vertex_3d* vel)
{
    obj->velocity.x = vel->x;
    obj->velocity.y = vel->y;
    obj->velocity.z = vel->z;
    return ST_OK;
}

st_state _st_object_GetVelocity(const st_object_info* obj, st_vertex_3d* vel)
{
    vel->x = obj->velocity.x;
    vel->y = obj->velocity.y;
    vel->z = obj->velocity.z;
    return ST_OK;
}

st_state _st_object_SetImage(st_object_info* obj, const st_uint8* imgfile)
{
    return st_graphic_LoadBitmap( &(obj->graphic), imgfile);
}

st_state _st_object_GetImage(const st_object_info* obj, st_graphic** graphic)
{
    *graphic = &(obj->graphic);
    return ST_OK; 
}

st_state _st_object_OnMoving(st_object_info* obj)
{
    obj->position.x += obj->velocity.x;
    obj->position.y += obj->velocity.y;
    obj->position.z += obj->velocity.z;
}

st_state st_object_Create(st_object_info* obj, 
                          const st_uint8* name,
                          const st_vertex_3d* pos,
                          const st_vertex_3d* vel,
                          const st_uint8* imgfile)
{
    if (_st_object_SetName(obj, name) == ST_ERROR)
    {
        return ST_ERROR;
    }

    if (_st_object_SetPosition(obj, pos))
    {
        return ST_ERROR;
    }
    if (_st_object_SetVelocity(obj, vel))
    {
        return ST_ERROR;
    }
    if (_st_object_SetImage(obj, imgfile))
    {
        return ST_ERROR;
    }

    return ST_OK;
}

st_state st_object_Free(st_object_info* obj)
{
    st_graphic_Free(&obj->graphic);
}

void _st_object_OnDrawing(void* arg)
{
    st_object_info* obj;

    obj = (st_object_info*)arg;
    
}

/*******************************************************************************
 *      Sparetime
 ******************************************************************************/

